package com.wwwarehouse.taskcenter.fragment.inventory_query;

import android.animation.ValueAnimator;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wwwarehouse.common.activity.base.BaseFragment;
import com.wwwarehouse.common.custom_widget.ElasticScrollView;
import com.wwwarehouse.common.custom_widget.X5WebView;
import com.wwwarehouse.common.custom_widget.progressbar.HorizontalProgressView;
import com.wwwarehouse.taskcenter.R;


/**
 * @创建者 chenchao.
 * @创建时间 2017/8/30 19:38
 * @描述 ${TODO}
 */
public class InventoryDistributionFragment extends BaseFragment implements View.OnClickListener {

    private View                   mView;
    private Button                 mBtMoreInv;
    private TextView               mTvCanUse;
    private View                   mVCanUse;
    private TextView               mTvInInv;
    private View                   mVInInv;
    private TextView               mTvGoodNum;
    private X5WebView              mWebInv;
    private TextView               mTvInvName1;
    private HorizontalProgressView mHpvInv1;
    private TextView               mTvInvName2;
    private HorizontalProgressView mHpvInv2;
    private TextView               mTvMoreInv;
    private LinearLayout mLlCanUdse;
    private LinearLayout mLlInInv;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mView = inflater.inflate(R.layout.fragment_inventory_dis, container, false);
        return mView;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initView();
    }

    private boolean isBtVisiable;
    private void initView() {
        mLlCanUdse = (LinearLayout) mView.findViewById(R.id.ll_can_use);
        mLlCanUdse.setOnClickListener(this);
        mTvCanUse = (TextView) mView.findViewById(R.id.tv_can_use);
        mVCanUse = mView.findViewById(R.id.v_can_use);

        mLlInInv = (LinearLayout) mView.findViewById(R.id.ll_in_inv);
        mLlInInv.setOnClickListener(this);
        mTvInInv = (TextView) mView.findViewById(R.id.tv_in_inv);
        mVInInv = mView.findViewById(R.id.v_in_inv);

        mTvGoodNum = (TextView) mView.findViewById(R.id.tv_good_num);
        mWebInv = (X5WebView) mView.findViewById(R.id.web_inv);
        mWebInv.loadUrl("http://www.baidu.com");
        mTvInvName1 = (TextView) mView.findViewById(R.id.tv_inv_name1);
        mHpvInv1 = (HorizontalProgressView) mView.findViewById(R.id.hpv_inv1);
        mTvInvName2 = (TextView) mView.findViewById(R.id.tv_inv_name2);
        mHpvInv2 = (HorizontalProgressView) mView.findViewById(R.id.hpv_inv2);
        mTvMoreInv = (TextView) mView.findViewById(R.id.tv_more_inv);
        mTvMoreInv.setOnClickListener(this);
        mBtMoreInv = (Button) mView.findViewById(R.id.bt_more_inv);
        mBtMoreInv.setOnClickListener(this);
        ElasticScrollView elasticScrollView = (ElasticScrollView) mView.findViewById(R.id.esv_elastic);
        elasticScrollView.setOnPullListener(new ElasticScrollView.OnPullListener() {
            @Override
            public void onDownPull() {

            }

            @Override
            public void onUpPull() {
                if (!isBtVisiable) {
                    mBtMoreInv.setVisibility(View.VISIBLE);
                    isBtVisiable = !isBtVisiable;
                } else {
                    mBtMoreInv.setVisibility(View.INVISIBLE);
                    isBtVisiable = !isBtVisiable;
                }
            }
        });
    }

    @Override
    public void setTitle() {
        if (peekFragment() instanceof InventoryDistributionFragment) {
            mActivity.setTitle(getString(R.string.inventory_distribution));
        }
    }

    @Override
    public void requestDatas() {
        mHpvInv1.setProgressAndTextColor(getResources().getColor(R.color.common_color_c1_337cff));
        ValueAnimator hpvAnimator = ValueAnimator.ofInt(0, mHpvInv1.getProgress());
        hpvAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animator) {
                //获得当前动画的进度值，整型，1-100之间
                int currentValue = (Integer) animator.getAnimatedValue();
                mHpvInv1.setProgress(currentValue);
            }
        });
        hpvAnimator.setDuration(1000);
        hpvAnimator.start();
    }

    @Override
    public void onClick(View v) {
        if (v == mLlCanUdse) {
            mTvCanUse.setTextColor(getResources().getColor(R.color.common_color_c1_337cff));
            mVCanUse.setVisibility(View.VISIBLE);
            mTvInInv.setTextColor(getResources().getColor(R.color.common_color_c4_121417));
            mVInInv.setVisibility(View.INVISIBLE);
        } else if (v == mLlInInv) {
            mTvCanUse.setTextColor(getResources().getColor(R.color.common_color_c4_121417));
            mVCanUse.setVisibility(View.INVISIBLE);
            mTvInInv.setTextColor(getResources().getColor(R.color.common_color_c1_337cff));
            mVInInv.setVisibility(View.VISIBLE);

        } else if (v == mTvMoreInv) {//跳转到更多进度条的页面

        } else if (v == mBtMoreInv) {//展示带抽屉的web界面

        }

    }
}
